from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException, NoSuchElementException # 还有更多的异常可以用
import time


def rest(sec):
    time.sleep(sec)

if __name__ == '__main__':
    browser = webdriver.Chrome()
    url = 'https://www.baidu.com'
    try:
        browser.get(url)
    except TimeoutException:
        print('超时异常')
    try:
        browser.find_element(By.ID, 'xxxx')
    except NoSuchElementException:
        print('找不到这个元素')
    finally:
        browser.close()